package cn.pengge.springaop.aspect;

import cn.pengge.springaop.annotation.Log;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class LogAspect {

    @Pointcut("@annotation(cn.pengge.springaop.annotation.Log)")
    public void pointCut(){

        System.out.println("进入切面方法了 ==================");
//        System.out.println("log = " + log);
    }

    @Before("pointCut()")
    public void before(JoinPoint joinPoint){
        System.out.println("进入切面之前了 ==================");
        System.out.println("joinPoint = " + joinPoint);
        MethodSignature signature = (MethodSignature)joinPoint.getSignature();
        Log annotation = signature.getMethod().getAnnotation(Log.class);
        String value = annotation.value();
        System.out.println(value);
    }

}
